package factory.simplefactory.order;

import factory.simplefactory.pizzasrore.Pizz;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author liangliangzhao
 * @data 2023/2/13 22:58
 */

public class OrderPizza {

    // 构造器
//    public OrderPizza(){
//        Pizz pizz = null;
//        String orderType; // 订购披萨的类型
//        do {
//            orderType = getType();
//            if(orderType.equals("greek")){
//                pizz = new GreekPizza();
//                pizz.setName("希腊披萨");
//            }else if(orderType.equals("cheese")){
//                pizz = new ChesssePizza();
//                pizz.setName("奶酪披萨");
//            }else if(orderType.equals("peper")){
//                pizz = new Peper();
//                pizz.setName("胡椒披萨");
//            }else {
//                break;
//            }
//            //输出pizza 执制作过程
//            pizz.prepare();
//            pizz.bake();
//            pizz.cut();
//            pizz.box();
//        }while (true);
//    }

    //定义一个简单工厂对象
    SimpleFactory factory;
    //定义一个披萨
    Pizz pizz = null;
    //构造器
    public OrderPizza(SimpleFactory factory){
        setFactory(factory);
    }
    public void setFactory(SimpleFactory simpleFactory){
        String orderType = "";//用户输入
        this.factory = simpleFactory;//设置一个简答工厂对象
        do{
            orderType = getType();//获取到想要的类型
            Pizz pizza = this.factory.createPizza(orderType);
            //输出pizza
            if(pizza != null){//订购成功
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购披萨失败");
                break;
            }
        }while (true);
    }
    //写一个方法 可以获取客户希望订购的披萨种类
    private String getType(){
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类");
            String str = strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}
